<!DOCTYPE html>
<html>
<head>
    <title>测试文件上传</title>
</head>
<body>
    <h2>测试头像上传</h2>
    <form id="uploadForm">
        <input type="file" id="fileInput" accept="image/*" required>
        <button type="submit">上传</button>
    </form>
    <div id="result"></div>

    <script>
        document.getElementById('uploadForm').addEventListener('submit', function(e) {
            e.preventDefault();
            
            const fileInput = document.getElementById('fileInput');
            const file = fileInput.files[0];
            
            if (!file) {
                alert('请选择文件');
                return;
            }
            
            const formData = new FormData();
            formData.append('file', file);
            
            fetch('http://localhost:8888/ele/user/uploadAvatar', {
                method: 'POST',
                body: formData
            })
            .then(response => response.json())
            .then(data => {
                document.getElementById('result').innerHTML = 
                    '<h3>上传结果:</h3><pre>' + JSON.stringify(data, null, 2) + '</pre>';
            })
            .catch(error => {
                document.getElementById('result').innerHTML = 
                    '<h3>错误:</h3><pre>' + error.message + '</pre>';
            });
        });
    </script>
</body>
</html> 